<%
layout("/layouts/platform.html"){
%>
	<header class="header navbar bg-white shadow">
		<div class="btn-group tool-button" style="padding:8px 0">
			<table>
           		<tbody>
           			<tr>
                  		<td>
                       		<input type="text" id="nameStr" name="nameStr" onclick="this.value=''" class="form-control" placeholder="主体名称" autofocus>
                        </td>
                        <td style="padding-left: 5px;">
                            <button id="searchBtn" type="button" class="btn btn-default"><i class="fa fa-search"></i>&nbsp;查询</button>
                      	</td>
                        </tr>
                    </tbody>
            </table>
		</div>
	    <div class="pull-right offscreen-right">
	         <a class="btn btn-default navbar-btn" href="${base}/platform/company/add" data-toggle="modal" data-target="#addModal" ><i class="fa fa-plus"></i>&nbsp;新增</a>
		</div>
	</header>
	<div class="panel-body" style="padding-top: 70px;">
		<div class="box">
			<div class="box-body">
				<div class="col-sm-12">
					<div class="row">
				        <table class="table table-bordered table-hover mg-t datatable">
				            <thead>
				            <tr>
								<th>名称</th>
								<th>编号</th>
								<th>加入时间</th>
								<th>状态</th>
								<th>操作</th>
				        </table>
	    			</div>
				</div>
			</div>
		</div>
	</div>
	<!-- 删除提示 -->
	<div id="dialogDelete" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
	    <div class="modal-dialog">
	        <div class="modal-content">
	            <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
	                <h4 class="modal-title">删除</h4>
	            </div>
	            <div class="modal-body">
	                <div class="row">
	                    <div class="col-xs-12">
	                        确定删除该数据吗？ <br/>
	                    </div>
	                </div>
	            </div>
	            <div class="modal-footer">
	                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
	                <button id="ok" type="button" class="btn btn-primary" >确定</button>
	            </div>
	        </div>
	    </div>
	</div>
	<!-- 修改-->
	<div id="editModal" class="modal fade bs-modal-sm"   tabindex="-3" role="dialog" aria-hidden="true">
	    <div id="editModalDialog" class="modal-dialog " >
	        <div class="modal-content">
	        
	        </div>
	    </div>
	</div>
	<!-- 新增-->
	<div id="addModal" class="modal fade bs-modal-sm"   tabindex="-3" role="dialog" aria-hidden="true">
	    <div id="addModalDialog" class="modal-dialog " >
	        <div class="modal-content">
	        
	        </div>
	    </div>
	</div>
	<script language="JavaScript">
		var datatable;
		//初始化数据
		function initDatatable() {
			datatable = $('.datatable').DataTable(
				{
					"dom" : '<"toolbar">frtip',
					"searching" : false,
					"processing" : true,
					"serverSide" : true,
					"select" : true,
					"ordering" : true,
					"language" : {
						"url" : "${base}/assets/plugins/datatables/cn.json"
					},
					"preDrawCallback" : function() {
						sublime.showLoadingbar($(".main-content"));
					},
					"drawCallback" : function() {
						sublime.closeLoadingbar($(".main-content"));
					},
					"ajax" : {
						"url" : "${base}/platform/company/data",
						"type" : "post",
						"data" : function(d) {
							d.name = $('#nameStr').val();
						}
					},
					"order" : [ [ 1, "desc" ] ],
					"columns" : [ 
					 	{"data" : "name","bSortable" : true}, 
					 	{"data" : "code","bSortable" : true}, 
					 	{"data" : "join_date","bSortable" : true}, 
					 	{"data" : "state","bSortable" : true} 
					],
					"columnDefs" : [
						{
							"render" : function(data, type, row) {
								if (data) {
									return moment(parseInt(data * 1000)).format("YYYY-MM-DD HH:mm:ss");
								}
								return '';
							},
							"targets" : 2
						},
						{
							"render" : function(data, type, row) {
								if (data == 0) {
									return "<font color='#3c8dbc'>正常</font>";
								} else if (data == -1) {
									return "<font color='#dd4b39'>未启用</font>";
								} else if (data == 1) {
									return "<font color='#9a9a9a'>停用</font>";
								} else {
									return "";
								}
							},
							"targets" : 3
						},
						{
							"render" : function(data, type, row) {
								return '<div>'
									 + '<a class="btn btn-xs btn btn-default " href="${base}/platform/company/edit/' + row.id + '" data-toggle="modal" data-target="#editModal"><i class="fa fa-edit"></i>&nbsp;修改</a> '
									 + '<a class="btn btn-xs btn btn-default " href="javascript:;" onclick="del(\''+ row.id+ '\')"><i class="glyphicon glyphicon-trash"></i>删除</a>'
									 + '</div>';
							},
							"targets" : 4
						} 
					]
			
				}
			);
			$("#searchBtn").on('click', function() {
				datatable.ajax.reload();
			});
		}
		//删除
		function del(id) {
			var dialog = $("#dialogDelete");
			dialog.modal("show");
			dialog.find("#ok").unbind("click");
			dialog.find("#ok").bind("click", function(event) {
				var btn = $(this);
				$.post("${base}/platform/company/delete/" + id, {}, function(data) {
					if (data.code == 0) {
						datatable.ajax.reload(null, false);
						dialog.modal("hide");
					} else {
						Toast.error(data.msg);
						dialog.modal("hide");
					}
				}, "json");
			});
		}
		$(function() {
			initDatatable();
			$("#addModal").on("hidden.bs.modal", function () {
	            $(this).removeData("bs.modal");
	        });
			$("#editModal").on("hidden.bs.modal", function () {
	            $(this).removeData("bs.modal");
	        });
		});
	</script>

<%}%>
